package com.fd.demo;

import java.util.Scanner;

public class MovieOperator {
    private Movie[] movies; //记住一个电影数组

    public MovieOperator(Movie[] movies) {
        this.movies = movies;
    }

    public void printAllMovies() {
        System.out.println("=============全部电影信息如下===========");
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            System.out.println(movie.getId() + " " + movie.getName() + " " + movie.getPrice() + " " + movie.getActor());
        }
        
    }
    // 根据id查询电影
    public void searchMovieById() {
        System.out.println("请输入要查询的id：");
        Scanner sc = new Scanner(System.in);
        int id = sc.nextInt();
        for (int i = 0; i < movies.length; i++) {
            // 拿到当前遍历到的电影对象
            Movie movie = movies[i];
            if (movie.getId() == id) {
                System.out.println(movie.getId() + " " + movie.getName() + " " + movie.getPrice() + " " + movie.getActor());
                return;
            }
        }
        System.out.println("没有找到该id对应的电影");
    }
}
